<?php
/**
 * 提交练习
 * Created by PhpStorm.
 * User: yaosj
 * Date: 16-5-21
 * Time: 下午4:22
 */
require __DIR__ . '/includes/utils.php';
require __DIR__ . '/includes/VipUtils.class.php';
class SubmitExercise implements iController {
    private static $MODULE_DIR;

    function __construct() {
        self::$MODULE_DIR  = __DIR__ . '/modules/';
    }

    public function output($queryArgs) {
        global $cmsdb;

        //不同的练习类型有不同的操作；
        //涉及到需要评论、批改的练习（申论批改、互评、字迹诊断等），做题记录更新history_primary_question_review
        //申论互评的练习，学员在完成之后会自动下发一个评论其它学员申论的练习

        if (validateUser($queryArgs) !== 1 || empty($queryArgs['exercise_id'])) {
            return genOutput(1000);
        }
        
        $userId     = $queryArgs['user_id'];
        $exerciseId = $queryArgs['exercise_id'];

        //获取作业及题目信息
        $exercise = $cmsdb->getRow('SELECT * FROM `data_primary_exercise` WHERE `id`=:id', array(':id' => $exerciseId));
        if (empty($exercise))
            return genOutput(1001);

        /**==========================================================
        | 根据不同作业科目、类型加载不同模块处理
        ----------------------------------------------------------*/
        switch ($exercise->type_id) {
            case 1: //申论作文-老师评
                require self::$MODULE_DIR.'ShenlunLectorModule.class.php';
                $exerciseModule = new ShenlunLectorModule();
                break;

            case 2: //申论作文-学生评
                require self::$MODULE_DIR.'HupingWriteModule.class.php';
                $exerciseModule = new HupingWriteModule();
                break;

            case 3: //字迹诊断
                require self::$MODULE_DIR.'ZijizhenduanModule.class.php';
                $exerciseModule = new ZijizhenduanModule();
                break;

            case 4: //词句摘抄
                require self::$MODULE_DIR.'CijuzhaichaoModule.class.php';
                $exerciseModule = new CijuzhaichaoModule();
                break;

            case 5: //表达改写
                require self::$MODULE_DIR.'BiaodagaixieModule.class.php';
                $exerciseModule = new BiaodagaixieModule();
                break;

            case 6: //语义提炼
                require self::$MODULE_DIR.'YuyitilianModule.class.php';
                $exerciseModule = new YuyitilianModule();
                break;

            case 7: //阅读打卡
                require self::$MODULE_DIR.'YuedudakaModule.class.php';
                $exerciseModule = new YuedudakaModule();
                break;

            case 8:  //行测智能组卷 - 综合
            case 21: //行测智能组卷 - 数量
            case 22: //行测智能组卷 - 资料
            case 23: //行测智能组卷 - 言语
            case 24: //行测智能组卷 - 判断
            case 42: //行测智能组卷 - 常识
                require self::$MODULE_DIR.'XingcezhinengModule.class.php';
                $exerciseModule = new XingcezhinengModule($exercise->type_id);
                break;

            case 9: //切磋互评
                require self::$MODULE_DIR.'HupingPostilModule.class.php';
                $exerciseModule = new HupingPostilModule();
                break;

            case 31: //速算
                require self::$MODULE_DIR.'SusuanSingleModule.class.php';
                $exerciseModule = new SusuanSingleModule();
                break;

            case 10: //申论套题
                require self::$MODULE_DIR.'ShenlunMultiModule.class.php';
                $exerciseModule = new ShenlunMultiModule();
                break;

            case 32: //找数
                require self::$MODULE_DIR.'ZhaoshuModule.class.php';
                $exerciseModule = new ZhaoshuModule();
                break;

            case 29: //解方程
                require self::$MODULE_DIR.'JiefangchengModule.class.php';
                $exerciseModule = new JiefangchengModule();
                break;

            case 30: //列方程
                require self::$MODULE_DIR.'LiefangchengModule.class.php';
                $exerciseModule = new LiefangchengModule();
                break;

            case 25: //判断推理 - 题型判定
            case 26: //言语 - 题型判定
            case 27: //资料 - 题型判定
            case 28: //数量 - 题型判定
            case 41: //常识判断 - 题型判定
                require self::$MODULE_DIR.'TixingpandingModule.class.php';
                $exerciseModule = new TixingpandingModule($exercise->type_id);
                break;

            case 43: //词语搭配
                require self::$MODULE_DIR.'CiyudapeiModule.class.php';
                $exerciseModule = new CiyudapeiModule();
                break;

            case 36: //成语积累
                require self::$MODULE_DIR.'ChengyujileiModule.class.php';
                $exerciseModule = new ChengyujileiModule();
                break;

            case 35: //实词积累
                require self::$MODULE_DIR.'ShicijileiModule.class.php';
                $exerciseModule = new ShicijileiModule();
                break;

            case 37: //文段找重点
                require self::$MODULE_DIR.'WenduanzhongdianModule.class.php';
                $exerciseModule = new WenduanzhongdianModule();
                break;

            case 39: //近义词辨析
                require self::$MODULE_DIR.'JinyicibianxiModule.class.php';
                $exerciseModule = new JinyicibianxiModule();
                break;

            case 40: //语境定位
                require self::$MODULE_DIR.'YujingdingweiModule.class.php';
                $exerciseModule = new YujingdingweiModule();
                break;

            case 38: //结构划分
                require self::$MODULE_DIR.'JiegouhuafenModule.class.php';
                $exerciseModule = new JiegouhuafenModule();
                break;

            case 33: //翻译推理
                require self::$MODULE_DIR.'FanyituiliModule.class.php';
                $exerciseModule = new FanyituiliModule();
                break;

            case 34: //公式
                require self::$MODULE_DIR.'GongshiModule.class.php';
                $exerciseModule = new GongshiModule();
                break;

            default:
                return genOutput(1001);
        }
        
        if (!empty($exerciseModule) && $exerciseModule->validateArgs($queryArgs)) {
            $data = $exerciseModule->submit($userId, $exercise);
            return genOutput(1, $data);
        } 

        return genOutput(1001);
    }
}